//检查个人用户登录
function checkCompanyReg(oForm){
	var company_name = str_trim($(oForm).find('#company_name').val());
	if(company_name == ''){
		layerMsg('公司名称不能为空!', 2);
		$(oForm).find('#company_name').focus();
		$(oForm).find('#company_name').val(company_name);
		return false;
	}

	var contacts = str_trim($(oForm).find('#contacts').val());
	if(contacts == ''){
		layerMsg('联系人不能为空!', 2);
		$(oForm).find('#contacts').focus();
		$(oForm).find('#contacts').val(contacts);
		return false;
	}

	var email = str_trim($(oForm).find('#email').val());
	if(email != ''){
		var regu = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if(!regu.test(email)){
			layerMsg('请输入正确的邮箱地址!', 2);
			$(oForm).find('#email').focus();
			$(oForm).find('#email').val(email);
			return false;
		}
	}

	var mobile = str_trim($(oForm).find('#mobile').val());
	if(mobile == ''){
		layerMsg('手机号码不能为空!', 2);
		$(oForm).find('#mobile').focus();
		$(oForm).find('#mobile').val(mobile);
		return false;
	}else if(mobile != ''){
		var regu = /(^1[3-9]{1}[0-9]{9}$)/g;
		if(!regu.test(mobile)){
			layerMsg('请输入正确的手机号码!', 2);
			$(oForm).find('#mobile').focus();
			$(oForm).find('#mobile').val(mobile);
			return false;
		}
	}

	var mob_code = str_trim($(oForm).find('#mobCode').val());
	if(mob_code == ''){
		layerMsg('验证码不能为空!', 2);
		$(oForm).find('#mobCode').focus();
		$(oForm).find('#mobCode').val(mob_code);
		return false;
	}

	var phone = str_trim($(oForm).find('#phone').val());
	if(phone != ''){
		var regu = /(^[0-9]{2,5}\-[0-9]{7,9})((\-\d{0,10})?)$/g;
		if(!regu.test(phone)){
			layerMsg('请输入正确的电话号码!', 2);
			$(oForm).find('#phone').focus();
			$(oForm).find('#phone').val(phone);
			return false;
		}
	}

	var username = str_trim($(oForm).find('#username').val());
	if(username == ''){
		layerMsg('用户名不能为空!', 2);
		$(oForm).find('#username').focus();
		$(oForm).find('#username').val(username);
		return false;
	}else{
		var regu =/^(?=[\u4e00-\u9fa5a-zA-Z])(?!\d+)[\u4e00-\u9fa5\w.]{6,20}$/;
		if(!regu.test(username)){
			layerMsg('用户名必须中英文开头6-20位数!', 2);
			$(oForm).find('#username').focus();
			$(oForm).find('#username').val(username);
			return false;
		}
	}

	//密码
	if($(oForm).find('#password').val() == '' || $(oForm).find('#password').val().length < 6){
		layerMsg('密码不能少于6位!', 2);
		$(oForm).find('#password').focus();
		return false;
	}
	//确认密码
	if($(oForm).find('#password_confirmation').val() != $(oForm).find('#password').val()){
		layerMsg('确认密码必须和新密码一致!', 2);
		$("#password_confirmation").focus();
		return false;
	}

	var queryString = $(oForm).serialize();
	$.ajax({
		url: '/mobile/company/register',
		dataType: "json",
		data: queryString,
		type: "POST",
		beforeSend: function(){
			$(oForm).find("input[type='submit']").val('请稍候...');
			$(oForm).find("input[type='submit']").attr('disabled', true);
		},
		success: function(data){
			if(data.status == '0'){
				layerMsg(data.msg, 2);
				location = data.registerBasic;
			}else{
				layerMsg('可能网络原因引起的错误！', 2);
				$(oForm).find("input[type='submit']").val('企业会员注册');
				$(oForm).find("input[type='submit']").removeAttr('disabled');
			}
		},
		error: function(data){
			var msgErr = '';
			var errors = $.parseJSON(data.responseText);
			$.each(errors, function(index, value){
				msgErr += "<p style='line-height: .4rem; width: 100%'>" + value + ";</p>";
			});
			layerMsg(msgErr, 2);
			$(oForm).find("input[type='submit']").val('企业会员注册');
			$(oForm).find("input[type='submit']").removeAttr('disabled');
		},
		complete: function(){
		}
	});
	return false;
}

//点击获取手机验证码
var mobTime;
var comSign = true;
function getMobileCode(othis, objMobile){
	var mobile = str_trim($(objMobile).val());
	if(mobile != ''){
		var mobValue = str_trim(mobile);
		var regu = /(^1[3-9]{1}[0-9]{9}$)/;
		if(regu.test(mobValue)){
			var src = 'this.src="' + imgCode + '" + Math.random()';
			var docSrc = 'document.getElementById("imgCodes").src="' + imgCode + '" + Math.random()';
			var str = "";
			str += "<div class='addCode'>";
			str += "<form method='post' name='mForm' id='mForm' onsubmit='return false'>";
			str += "<span><input name='code' id='code' type='text'  placeholder='验证码' class='code' ></span>";
			str += "<span><img id='imgCodes' src='" + imgCode + Math.random() + "' onclick='" + src + "' /></span>";
			str += "<span class='change'><a onclick='" + docSrc + "'>换一换</a></span>";
			str += "<div class='codeErr' id='codeErr'></div>";
			str += "</form>";
			str += "</div>";


			layer.open({
				title: [
					'请输入验证码',
					'background-color:#00c6c9; color:#fff; height:.8rem; line-height:.8rem'
				]
				, className: 'loginCode' //自定风格
				, content: str
				, shadeClose: false
				, style: 'font-family:微软雅黑; font-size:.28rem'
				, btn: ['确认', '取消']
				, yes: function(index){
					var code = $("#mForm").find("#code").val();
					$.post('/common/ajax_code', {'_token': _token, 'code': code}, function(data){
						if(data == 'true'){
							$.post('/company/ajax_mob_code', {
								'_token': _token,
								'mobile': mobValue,
								'code': code
							}, function(data){
								if(data.status == 2){
									//验证手机号码是不是存在
									//layerMsg(data.msg, 2);.
									layer.open({
										title: [
											'该手机号码已经被注册,请选择操作方式',
											'background-color: #FF4351; color:#fff;'
										]
										, shadeClose: false
										, className: 'layer-btn' //自定风格
										, content: '<div class="layui-layer-btn">' +
										'<a class="layui-layer-btn0"  href="/mobile/company/find_password?mobile=' + mobValue + '">找回密码</a>' +
										'<a class="layui-layer-btn1" href="/mobile/company/login?mobile=' + mobValue + '">马上登录</a>' +
										'<a class="layui-layer-btn2" onclick="carryon()">继续注册</a>' +
										'</div>'
									});
								}else if(data.status == 1){
									//获取验证码成功
									layerMsg(data.msg, 2);
									var iNum = 60;
									mobTime = setInterval(function(){
										iNum -= 1;
										othis.attr("disabled", true).val('(' + iNum + ')秒后重新获取').css({
											"background": "#ccc",
											"color": "#333"
										});
										if(iNum <= 0){
											othis.removeAttr("disabled").val('获取验证码').css({
												"background": "#505962",
												"color": "#fff"
											});
											clearInterval(mobTime);
										}
									}, 1000);
								}else if(data.status == 0){
									//验证码获取失败
									layerMsg(data.msg, 2);
								}
							});
						}else{
							$("#mForm").find("#codeErr").html('验证码错误');
						}
					});
				}
			});
		}else{
			objMobile.val(str_trim(mobile));
			layerMsg('请输入正确的手机号码!', 2);
		}
	}else{
		objMobile.val(str_trim(mobile));
		layerMsg('请填写手机号码!', 2);
	}
}

/**
 * 手机号码注册
 */
function carryon(){
	layerMsg('手机号码已经注册，请重新输入', 2);
	$("#regForm").find("#mobile").focus();
}
